<template>
  <view class="">
    <view class="exhibit" v-if="Collection.length != 0">
      <view class="Collection">
        <view class="Collection_top">
          <span>我的藏品 ({{ lenthts }})</span>
          <image
            :src="
              !GongGestate
                ? '/static/Collections.png'
                : '/static/Collection.png'
            "
            style="width: 44rpx; height: 44rpx"
            @click="GongGe()"
          ></image>
        </view>
        <view :class="!GongGestate ? 'Collection_item' : 'CollectionNew_item'">
          <block v-for="(item, index) in Collection" :key="index">
            <view class="Collection_img" @click="toCollection(item, index)">
              <view
                :class="!GongGestate ? 'quantity' : 'quantitynew'"
                v-if="item.num != 1"
                >{{ item.num }}</view
              >
              <view class="">
                <image
                  :src="item.cover"
                  :class="
                    !GongGestate ? 'Collection_image' : 'CollectionNew_image'
                  "
                ></image>
              </view>
              <view class="Collection_right">
                <text class="Collection_right_text">{{ item.name }}</text>
                <view>
                  <image
                    src="/static/collect_icon.png"
                    style="width: 44rpx; height: 44rpx"
                    class="item_farstimg"
                  ></image>
                  <text class="item_center">{{ item.no }}</text>
                </view>
                <view
                  style="display: flex; align-items: center; margin-top: 20rpx"
                >
                  <image
                    :src="item.creator_avatar"
                    style="
                      width: 34rpx;
                      height: 34rpx;
                      margin-right: 10rpx;
                      border-radius: 50rpx;
                    "
                  ></image>
                  <text style="font-size: 24rpx">{{ item.creator_name }}</text>
                </view>
              </view>
            </view>
          </block>
        </view>
      </view>
    </view>
    <empty :show.sync="Collection.length == 0 && pagestate"></empty>
  </view>
</template>

<script>
import api from "@/api/api.js";
import tip from "@/utils/tip.js";
import moment from "moment";
import { isLogin } from "@/utils/auth.js";
import empty from "@/components/empty/empty";
export default {
  components: {
    empty,
  },
  data() {
    return {
      widHeigh: 0,

      page: 1,
      limit: 10,
      pagestate: false,

      userInfo: null,

      GongGestate: false, //宫格状态
      Collection: [],
      lenthts: 0,
    };
  },
  onLoad() {
    let windowElement = uni.getSystemInfoSync();
    this.widHeigh = windowElement.windowHeight;
  },
  onShow() {
    this.userInfo = uni.getStorageSync("userInfo");
    this.getproducts();
  },
  computed: {
    is_Coming_soon() {
      return (time) => {
        return moment(time).diff(moment(), "second") > 0;
      };
    },
  },
  methods: {
    async toCollection(itme, index) {
      if (itme.num != 1) {
        uni.navigateTo({
          url: `../../pages/collectionNewlist/collectionNewlist?product_id=${itme.product_id}`,
        });
        return;
      }
      uni.navigateTo({
        url: `../../pages/collect_record/collect_record?user_product_id=${itme.first_user_product.id}`,
      });
    },
    GongGe() {
      this.GongGestate = !this.GongGestate;
    },
    async getproducts() {
      // let userInfo = uni.getStorageSync('userInfo')
      // console.log(userInfo.id,'uni.getStod')

      let res = await api.stackingProducts({
        query: {
          // user_id:this.userInfo.id,
          page: this.page,
        },
      });
      uni.stopPullDownRefresh();
      if (res.code == 0) {
        if (this.page == 1) {
          this.Collection = res.data;
          if (res.data.length == 0) {
            this.pagestate = true;
          }
        } else {
          this.Collection = [...this.Collection, ...res.data];
        }
        this.lenthts =
          this.userInfo.user_product_num + this.userInfo.blind_box_num;
        //  if(this.page==1){
        // 	  if(res.data.length>0){
        // 		  this.Collection = res.data;
        // 		  this.Collection.forEach(x => {
        // 						x.product_snap = JSON.parse(x.product_snap)
        // 		  })
        // 		  this.lenthts = this.userInfo.user_product_num + this.userInfo.blind_box_num
        // 	  }else{
        // 		  this.pagestate = true
        // 	  }
        //  }else{
        // 		 if(res.data.length>0){
        // 			 res.data.forEach(x => {
        // 			 		x.product_snap = JSON.parse(x.product_snap)
        // 			 })
        // 		 	this.Collection = [...this.Collection,...res.data]
        // 		 	// res.data.forEach((el,index) => {
        // 		 	// 	this.Collection.push(res.data[index])
        // 		 	// })
        // 			 console.log(this.Collection,'+++++++++');
        // 		 }
        //  }
      }
    },

    onReachBottom() {
      this.page++;
      this.getproducts();
    },
    // 页面下拉刷新
    onPullDownRefresh() {
      this.page = 1;
      this.getproducts();
    },
  },
};
</script>

<style>
page {
  background-color: #0c0d0d;
}
</style>

<style lang="scss" scoped>
@import "../../style/yuanchuang.scss";
.content {
  width: 690rpx;
  font-family: PingFangSC-Regular, PingFang SC;
  padding: 0 30rpx 0 30rpx;
  background: $bg-color1;

  // background-image: url(../../static/index_bg.png);
  // background-repeat: no-repeat;
  // background-size: 100% 510rpx;
}

.search {
  width: 690rpx;
  height: 88rpx;
  display: flex;
  align-items: center;
  justify-content: space-between;
  &_logo {
    width: 192rpx;
    height: 54rpx;
  }
  &_icon {
    width: 40rpx;
    height: 40rpx;
  }
}
.top {
  width: 690rpx;
  height: 280rpx;
  background: black;
  border-radius: 24rpx;
  &_image1 {
    width: 690rpx;
    height: 280rpx;
  }
}
.u-tabs_line {
  display: flex;
  position: relative;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  .u-tabs_wrapper {
    width: 70%;
  }
}
.exhibit {
  overflow: hidden;
  &_item {
    width: 690rpx;
    height: 904rpx;
    background: #1d1d28;
    border-radius: 36rpx;
    &_wrapper {
      position: relative;
      width: 690rpx;
      height: 690rpx;
    }
    &_timer {
      z-index: 1;
      position: absolute;
      top: 26rpx;
      left: 26rpx;

      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 20rpx;
      // width: 408rpx;
      height: 60rpx;
      background: #000000;
      border-radius: 30rpx;
      // opacity: 0.46;
      background-color: rgba(0, 0, 0, 0.46);
    }
    &_timerIcon {
      width: 32rpx;
      height: 32rpx;
    }
    &_timerText {
      margin-left: 8rpx;
      font-size: 28rpx;
      font-weight: 400;
      color: #f78623;
      line-height: 40rpx;
      // opacity: 0.46;
    }
    &_sale1 {
    }
    &_sale2 {
      margin-left: 12rpx;
    }
    &_goodsImage {
      border-radius: 36rpx;
      width: 690rpx;
      height: 690rpx;
    }
    &_bottom {
      display: flex;
      align-items: center;
      justify-content: space-between;
    }
    &_left {
      margin: 30rpx 0 0 30rpx;
    }
    &_right {
      height: 138rpx;
      margin: 46rpx 30rpx 0 0;
    }
    &_first {
      width: 400rpx;
      height: 44rpx;
      font-size: 32rpx;
      font-weight: 500;
      color: #ffffff;
      line-height: 44rpx;

      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    &_second {
      display: flex;
      align-items: center;

      margin: 20rpx 0;
      font-size: 24rpx;
      font-weight: 400;
      color: #ffffff;
      line-height: 34rpx;

      // width: 202rpx;
      height: 34rpx;
      border-radius: 4rpx;
    }
    &_limited {
      // width: 76rpx;
      padding: 0 14rpx;
      height: 34rpx;
      background: linear-gradient(130deg, #f78623 0%, #d5280a 100%);
      border-radius: 4rpx;
      text-align: center;
    }
    &_inStock {
      padding: 0 14rpx;
      // margin-left: 10rpx;
      font-size: 24rpx;
      font-weight: 400;
      color: #ffffff;
      line-height: 34rpx;
      background: #262934;
    }
    &_third {
      display: flex;
      align-items: center;

      font-size: 26rpx;
      font-weight: 500;
      color: #ffffff;
      line-height: 36rpx;
    }
    &_avatar {
      border-radius: 50%;
      margin-right: 8rpx;
      width: 36rpx;
      height: 36rpx;
    }
    &_username {
      font-size: 26rpx;
      font-weight: 500;
      color: #ffffff;
      line-height: 36rpx;
    }
    &_button {
      margin-left: calc(100% - 116rpx);
      width: 116rpx;
      height: 56rpx;
      border-radius: 28rpx;
      text-align: center;

      font-size: 28rpx;
      font-weight: 400;
      line-height: 56rpx;
      color: $text-color4;
      background: $button;background-repeat: no-repeat;background-size: 100%;
    }
    &_buttonGray {
      margin-left: calc(100% - 116rpx);
      width: 116rpx;
      height: 56rpx;
      background: #999999;
      border-radius: 28rpx;
      text-align: center;

      font-size: 28rpx;
      font-weight: 400;
      color: #ffffff;
      line-height: 56rpx;
    }
    &_price {
      margin-top: 34rpx;
      font-size: 40rpx;
      font-family: SFPro-Bold, SFPro;
      font-weight: bold;
      color: #ffffff;
      line-height: 48rpx;
    }
  }
  &_item:not(:first-child) {
    margin-top: 30rpx;
  }
  &_item:last-child {
    margin-bottom: 30rpx;
  }
}
.Collection {
  color: #ffffff;
  font-size: 32rpx;
  margin: 40rpx 30rpx;
}
.Collection_top {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20rpx;
}
.CollectionNew_item {
  display: flex;
  justify-content: space-between;
  flex-direction: row;
  align-items: flex-start;
  flex-wrap: wrap;
  position: relative;

  /* align-items: flex-start;
		margin:30rpx 0; */
  .Collection_img {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
    background-color: #1c1e27;
    border-radius: 24rpx;
    margin: 15rpx 0 15rpx 0;
    width: 48%;
    height: 540rpx;

    background-image: url("/static/backgroundNew.png");
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;

    .CollectionNew_image {
      width: 330rpx;
      height: 330rpx;
      border-radius: 24rpx;
    }

    .Collection_right {
      margin-left: 30rpx;
      padding: 20rpx 0;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      align-items: flex-start;
      // height: 200rpx;
      .Collection_right_text {
        font-size: 28rpx;
        // padding-top: 15rpx;
        overflow: hidden;
        -webkit-line-clamp: 1;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
      }
    }
  }
}
.Collection_item {
  display: flex;
  justify-content: space-between;
  flex-direction: column;
  align-items: flex-start;

  .Collection_img {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    background-color: #1c1e27;
    border-radius: 24rpx;
    margin: 15rpx 0 15rpx 0;
    width: 100%;
    height: 240rpx;
    position: relative;

    background-image: url("/static/background.png");
    background-repeat: no-repeat;
    background-position: center;
    /* background-attachment: fixed; */
    background-size: cover;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    .Collection_image {
      width: 240rpx;
      height: 240rpx;
      border-radius: 24rpx;
      margin-top: 10rpx;
    }

    .Collection_right {
      margin-left: 30rpx;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      height: 200rpx;
      .Collection_right_text {
        font-size: 28rpx;
        // padding-top: 15rpx;
        overflow: hidden;
        -webkit-line-clamp: 2;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
      }
    }
  }
}
.item_center {
  position: relative;
  left: -30rpx;
  font-size: 20rpx;
  padding: 5rpx 10rpx 5rpx 26rpx;
  border-radius: 17rpx;
  color: $text-color4;
  background-image: $button;
}
.item_farstimg {
  z-index: 2;
  position: relative;
  top: 14rpx;
  left: -2rpx;
}
.quantity {
  position: absolute;
  top: 0;
  left: 170rpx;
  color: #ffffff;
  z-index: 2;
  min-width: 28px;
  height: 28px;
  line-height: 36rpx;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 25px;
  text-align: center;
  margin-top: 20rpx;
  font-size: 28rpx;
  padding: 10rpx;
}
.quantitynew {
  position: absolute;
  margin-left: 260rpx;
  color: #ffffff;
  z-index: 2;
  min-width: 28px;
  height: 28px;
  line-height: 36rpx;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 25px;
  text-align: center;
  margin-top: 20rpx;
  font-size: 28rpx;
  padding: 10rpx;
}
</style>
